import 'package:flutter_demo/ui/pages/getx/count/conut_state.dart';
import 'package:get/get.dart';

//业务逻辑
class CountController extends GetxController {
  final CountState state = CountState();
  static CountController get to => Get.find();
  addSimpleCount() {
    state.simpleCount++;
    //更新页面计数器变量
    update(["test1"]);
  }

  getSimpleCount() => state.simpleCount;

  get() {
    //print("===");
    return state.count;
  }

  add() => state.count++;

  //CountController 被put 收被调用
  @override
  void onInit() {
    print("CountController 初始化了");

    //state.count 变化时候被监听
    ever(state.count, (callback) {
      print("ever 变化了：" + callback.toString());
    });

    //state.count 第一次变化是后被监听
    once(state.count, (callback) {
      print("once 变化了：" + callback.toString());
    });

    //变化间隔指定时间触发
    debounce(state.count, (callback) {
      print("debounce 变化了：" + callback.toString());
    }, time: Duration(seconds: 1));

    //忽略1秒内的操作
    interval(state.count, (callback) {
      print("interval 变化了：" + callback.toString());
    }, time: Duration(seconds: 1));
  }

  @override
  void onClose() {}
}
